﻿/*
 * Created by SharpDevelop.
 * User: Christian Pacella
 * Date: 2010/10/29
 * Time: 11:14 PM
 */
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace Crianthis.MiniCompiler
{
	/// <summary>
	/// Description of ConfigForm.
	/// </summary>
	public partial class ConfigForm : Form
	{
		// Create the customer object we want to display
		MiniApp myApp = new MiniApp();
			
		public ConfigForm()
		{
			InitializeComponent();
		}
		
		void ConfigFormLoad(object sender, EventArgs e)
		{
			try
			{
				// Construct an instance of the XmlSerializer with the type
				// of object that is being deserialized.
				XmlSerializer mySerializer = 
				new XmlSerializer(typeof(MiniApp));
				
				// To read the file, create a FileStream.
				FileStream myFileStream = 
				new FileStream("myApp.xml", FileMode.Open);
				
				// Call the Deserialize method and cast to the object type.
				myApp = (MiniApp) 
				mySerializer.Deserialize(myFileStream);
				
				myFileStream.Close();
			}
			catch
			{
				
			}
			
			// Sets the the grid with the myApp instance to be browsed
			propertyGrid.SelectedObject = myApp;
		}
		
		void ConfigFormFormClosing(object sender, FormClosingEventArgs e)
		{
			// Insert code to set properties and fields of the object.
			XmlSerializer mySerializer = new 
			XmlSerializer(typeof(MiniApp));
			
			// To write to a file, create a StreamWriter object.
			StreamWriter myWriter = new StreamWriter("myApp.xml");
			mySerializer.Serialize(myWriter, myApp);
			
			myWriter.Close();
		}
		
		void CloseButtonClick(object sender, EventArgs e)
		{
			// Close the form.
			this.Close();
		}
	}
}
